package com.wuzheng.wisgo.sanitation.cloud.repository.mapper.roadandstate;

import com.wuzheng.wisgo.sanitation.cloud.model.roadandstatus.RoadInfoDto;
import com.wuzheng.wisgo.sanitation.cloud.model.roadandstatus.TrashLngLatDto;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.jobcompletion.JobCompletionTrashItem;
import com.wuzheng.wisgo.sanitation.cloud.repository.handler.ArrayType2Handler;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/*
 * @Description:
 * @Author: sunpeng
 * @Date: 2019/12/18
 **/
public interface RouteStateMapper {

    /*
     * @Description: 根据vin码查询垃圾桶
     * @Author: sunpeng
     * @Date: 2019/12/18
     **/
    @Select("SELECT bjpv.veh_vin_code,bjpt.route_id,bjpt.trash_id,bjpt.plan_id,bjpt.trash_long,bjpt.trash_lat,bjpt.error_threshold\n" +
            "FROM ba_job_plan_vehicle bjpv\n" +
            "LEFT JOIN ba_job_plan_transfer bjpt ON bjpv.plan_id=bjpt.plan_id AND bjpt.de_flag=FALSE\n" +
            "WHERE bjpv.veh_vin_code=#{vehVinCode}")
    List<TrashLngLatDto> selectTranshFromJobPlan(@Param("vehVinCode") String vehVinCode);

    /*
     * @Description: 查询车辆停留在垃圾桶时段内的数据
     * @Author: sunpeng
     * @Date: 2019/12/18
     **/
    @Select("SELECT id, trash_id,veh_vin,trash_long,trash_lng,t_long,t_lng,rec_collection_time,create_time\n" +
            "FROM ba_job_completion_trash_item\n" +
            "WHERE trash_long=#{trashLong} \n" +
            "AND trash_lng=#{trashLng}" +
            "ORDER BY rec_collection_time ASC")
    List<JobCompletionTrashItem> selectBaJobCompletionTrashItem(@Param("trashLong") Double trashLong, @Param("trashLng") Double trashLng);

    /*
     * @Description: 通过vin码查询道路信息
     * @Author: sunpeng
     * @Date: 2019/12/18
     **/
    @Select("SELECT bjpv.veh_vin_code,bjpv.plan_id,bjpr.road_id,bjr.gps_features ,bjpr.gps_offset\n" +
            "FROM ba_job_plan_vehicle bjpv\n" +
            "LEFT JOIN ba_job_plan_road bjpr ON bjpv.plan_id=bjpr.plan_id\n" +
            "LEFT JOIN ba_job_road bjr ON bjpr.road_id=bjr.id\n" +
            "WHERE bjpv.veh_vin_code=#{vehVin}")
    @Results(@Result(column = "gps_features", property = "gpsFeatures", typeHandler = ArrayType2Handler.class))
    List<RoadInfoDto> selectRoadFromVehVin(@Param("vehVin") String vehVin);
}
